//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import payList from './common/payList.vue';
import pledgeRecord from './common/pledgeRecord.vue';
import deductPopup from './common/deductPopup.vue';
import { scrollMixin } from "utils/mixin";  
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {
    payList,
    pledgeRecord,
    deductPopup
  },
  mixins: [scrollMixin], //加载更多
  data() {
  return {
    payId:'',
    paymentIndex:0, //切换分类的索引
    cashIndex:0, //切换分类的索引
    payActive:0,
    deductShow:false,
    status:"",
    isLoadMore: true,
    page: 1,
    total_page: 0,
    paylogList:[],
    deductionData:[], //扣款记录
    paymentList:[
      {
        name:'全部',
        index:0,
        status:''
      },
      {
        name:'进行中',
        index:1,
        status:1
      },
      {
        name:'已完成',
        index:2,
        status:3
      },
      {
        name:'失效',
        index:3,
        status:-1
      }
    ],
    cashList: [
      {
        name:'全部',
        status:'',
        index:0
      },
      {
        name:'待结算',
        index:1,
        status:0
      },
      {
        name:'已结算',
        index:2,
        status:1
      },
      {
        name:'已失效',
        index:3,
        status:-1
      }
    ],
    api:'plugin.alipay-period-deduct.frontend.index.pay-log',
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    paymentOn(index,status,type) {
      type === 0 ?this.paymentIndex = index:this.cashIndex = index;
      this.paymentIndex = index;
      this.status = status;
      this.page = 1;
      this.paylogData();
    },
    // cashOn(index) {
    //   this.cashIndex = index;
    //   this.status = status;
    //   this.paylogData();
    // },
    recordClick(data) {
      this.payId = data;
      this.deductShow = true;
      this.deductionLog();
    },
    deductOpen(data) {
      this.deductShow = data;
      console.log(this.deductShow);
    },
    payChange(event) {
      console.log(event);
      this.payActive = event;
      this.status = '';
      this.cashIndex = 0;
      this.paymentIndex = 0;
      this.page = 1;
      if(this.payActive === 0) {
        this.api = 'plugin.alipay-period-deduct.frontend.index.pay-log';
      } else {
        this.api = 'plugin.alipay-period-deduct.frontend.index.security-log';
      }
      this.paylogData();
    },
    paylogData() {
      $http.post(this.api, {status:this.status,page:this.page,basic_info:1}, "加载中..").then(response => {
        if (response.result == 1) {
          let basicInfo = response.basic_info;
          let res = response.data;
          let list = res?.list?.data;
          console.log(res);
          this.paylogList = list;
          this.isLoadMore = true;
          this.total_page = res.list?.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.$nextTick(() => {
            this.fun.wxShare(
              "",
              { mid: this.fun.getKeyByMid() },
              {
                link: window.location.href,
                title: basicInfo?.home.mailInfo?.name,
                imgUrl: basicInfo?.home.mailInfo?.logo_url,
                description: ''
              }
            );
          },50);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    deductionLog() {
      $http.get("plugin.alipay-period-deduct.frontend.index.deduction-log", {id:this.payId}, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          let basicInfo = response.basic_info;
          let list = res?.list;
          this.deductionData = list;
          console.log(list);
        } else {
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        if(this.payActive === 0) {
          this.api = 'plugin.alipay-period-deduct.frontend.index.pay-log';
        } else {
          this.api = 'plugin.alipay-period-deduct.frontend.index.security-log';
        }
        $http.post(this.api, { page: this.page,status:this.status }, "加载中").then(
          response => {
            this.isLoadMore = true;
            if (response.result === 1) {
              let res = response.data;
              let list = res?.list?.data;
              console.log(list);
              this.paylogList = [...this.paylogList, ...list]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            // error callback
          }
        );
      }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    if(this.payActive === 0) {
      this.api = 'plugin.alipay-period-deduct.frontend.index.pay-log';
    } else {
      this.api = 'plugin.alipay-period-deduct.frontend.index.security-log';
    }
    this.paylogData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }